package com.alex.index.create;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch.indices.CreateIndexResponse;
import com.alex.common.config.IndexConfig;
import com.alex.utils.EsClient;

@SuppressWarnings("ALL")
public class A_CreateIndex_Reference {

    public static void main(String[] args) throws Exception {
        start();
    }


    public static void start() throws Exception {

        // 创建连接
        ElasticsearchClient client = EsClient.client();
        CreateIndexResponse createIndexResponse =
                client.indices()
                        .create(c -> c.index(IndexConfig.REFERENCE_INDEX)/*这个是Index名字,可以直接字符串*/
                                .settings(indexSettingsBuilder -> indexSettingsBuilder
                                        .numberOfReplicas("0")
                                        .numberOfShards("8")
                                )
                                .mappings(o -> o
                                        .properties("id", i -> i.text(p -> p))
                                        .properties("aid", i -> i.integer(p -> p))
                                        .properties("article", i -> i.text(p -> p.analyzer("standard").searchAnalyzer("standard")))//句子
                                        .properties("pmid", i -> i.integer(p -> p))//pmid
                                        .properties("addr", i -> i.text(p -> p))//位置
                                        .properties("cite", i -> i.text(p -> p))//所有参文
                                        .properties("jour", i -> i.text(p -> p))//所有参文
                                        .properties("year", i -> i.integer(p -> p))
                                        .properties("is_cns", i -> i.integer(p -> p))
                                        .properties("jcr_if", i -> i.double_(p -> p))
                                ));

        // 打印结果
        System.out.println(createIndexResponse.acknowledged());
        EsClient.clientOff();

    }


}
